<?php

/**
 * This is the model class for table "user".
 *
 * The followings are the available columns in table 'user':
 * @property string $ID_USER
 * @property integer $KODE_TOKO
 * @property string $ID_KOTA
 * @property integer $ID_ROLE
 * @property string $NAMA
 * @property string $EMAIL
 * @property string $PASSWORD
 * @property string $ALAMAT
 * @property string $NOMOR_KTP
 * @property string $NOMOR_TELEPON
 * @property string $TANGGAL_LAHIR
 * @property string $JENIS_KELAMIN
 *
 * The followings are the available model relations:
 * @property Pemesanan[] $pemesanans
 * @property Role[] $roles
 * @property Testimoni[] $testimonis
 * @property Toko[] $tokos
 * @property Kota $iDKOTA
 * @property Role $iDROLE
 * @property Toko $kODETOKO
 * @property Whislist[] $whislists
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ID_USER, NAMA, EMAIL, PASSWORD, NOMOR_KTP, JENIS_KELAMIN', 'required'),
			array('KODE_TOKO, ID_ROLE', 'numerical', 'integerOnly'=>true),
			array('ID_USER', 'length', 'max'=>8),
			array('ID_KOTA', 'length', 'max'=>40),
			array('NAMA, EMAIL, PASSWORD', 'length', 'max'=>30),
			array('ALAMAT, NOMOR_KTP, NOMOR_TELEPON, JENIS_KELAMIN', 'length', 'max'=>102),
			array('TANGGAL_LAHIR', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID_USER, KODE_TOKO, ID_KOTA, ID_ROLE, NAMA, EMAIL, PASSWORD, ALAMAT, NOMOR_KTP, NOMOR_TELEPON, TANGGAL_LAHIR, JENIS_KELAMIN', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'pemesanans' => array(self::HAS_MANY, 'Pemesanan', 'ID_USER'),
			'roles' => array(self::HAS_MANY, 'Role', 'ID_USER'),
			'testimonis' => array(self::HAS_MANY, 'Testimoni', 'ID_USER'),
			'tokos' => array(self::HAS_MANY, 'Toko', 'ID_USER'),
			'iDKOTA' => array(self::BELONGS_TO, 'Kota', 'ID_KOTA'),
			'iDROLE' => array(self::BELONGS_TO, 'Role', 'ID_ROLE'),
			'kODETOKO' => array(self::BELONGS_TO, 'Toko', 'KODE_TOKO'),
			'whislists' => array(self::HAS_MANY, 'Whislist', 'ID_USER'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID_USER' => 'Id User',
			'KODE_TOKO' => 'Toko',
			'ID_KOTA' => 'Kota',
			'ID_ROLE' => 'Role',
			'NAMA' => 'Nama',
			'EMAIL' => 'Email',
			'PASSWORD' => 'Password',
			'ALAMAT' => 'Alamat',
			'NOMOR_KTP' => 'Nomor Ktp',
			'NOMOR_TELEPON' => 'Nomor Telepon',
			'TANGGAL_LAHIR' => 'Tanggal Lahir',
			'JENIS_KELAMIN' => 'Jenis Kelamin',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID_USER',$this->ID_USER,true);
		$criteria->compare('KODE_TOKO',$this->KODE_TOKO);
		$criteria->compare('ID_KOTA',$this->ID_KOTA,true);
		$criteria->compare('ID_ROLE',$this->ID_ROLE);
		$criteria->compare('NAMA',$this->NAMA,true);
		$criteria->compare('EMAIL',$this->EMAIL,true);
		$criteria->compare('PASSWORD',$this->PASSWORD,true);
		$criteria->compare('ALAMAT',$this->ALAMAT,true);
		$criteria->compare('NOMOR_KTP',$this->NOMOR_KTP,true);
		$criteria->compare('NOMOR_TELEPON',$this->NOMOR_TELEPON,true);
		$criteria->compare('TANGGAL_LAHIR',$this->TANGGAL_LAHIR,true);
		$criteria->compare('JENIS_KELAMIN',$this->JENIS_KELAMIN,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}